using System;
using NUnit.Framework;
using DotNetXmlSwfChart;

namespace DotNetXmlSwfChart.UnitTest
{
    [TestFixture]
    public class DrawRectangleFixture
    {
        [Test]
        public void DrawRectangleBackgroundLayerDissolveTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.dissolve);
        }

        [Test]
        public void DrawRectangleForegroundLayerDissolveTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.dissolve);
        }

        [Test]
        public void DrawRectangleBackgroundLayerDropTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.drop);
        }

        [Test]
        public void DrawRectangleForegroundLayerDropTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.drop);
        }

        [Test]
        public void DrawRectangleBackgroundLayerSpinTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.spin);
        }

        [Test]
        public void DrawRectangleForegroundLayerSpinTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.spin);
        }

        [Test]
        public void DrawRectangleBackgroundLayerScaleTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.scale);
        }

        [Test]
        public void DrawRectangleForegroundLayerScaleTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.scale);
        }

        [Test]
        public void DrawRectangleBackgroundLayerZoomTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.zoom);
        }

        [Test]
        public void DrawRectangleForegroundLayerZoomTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.zoom);
        }

        [Test]
        public void DrawRectangleBackgroundLayerBlinkTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.blink);
        }

        [Test]
        public void DrawRectangleForegroundLayerBlinkTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.blink);
        }

        [Test]
        public void DrawRectangleBackgroundLayerSlideRightTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.slide_right);
        }

        [Test]
        public void DrawRectangleForegroundLayerSlideRightTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.slide_right);
        }

        [Test]
        public void DrawRectangleBackgroundLayerSlideLeftTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.slide_left);
        }

        [Test]
        public void DrawRectangleForegroundLayerSlideLeftTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.slide_left);
        }

        [Test]
        public void DrawRectangleBackgroundLayerSlideUpTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.slide_up);
        }

        [Test]
        public void DrawRectangleForegroundLayerSlideUpTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.slide_up);
        }

        [Test]
        public void DrawRectangleBackgroundLayerSlideDownTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.slide_down);
        }

        [Test]
        public void DrawRectangleForegroundLayerSlideDownTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.slide_down);
        }

        [Test]
        public void DrawRectangleBackgroundLayerNoTransition()
        {
            RectangleTest(DrawLayer.background, TransitionType.none);
        }

        [Test]
        public void DrawRectangleForegroundLayerNoTransition()
        {
            RectangleTest(DrawLayer.foreground, TransitionType.none);
        }

        private void RectangleTest(DrawLayer layer, TransitionType type)
        {
            string testXml =
                "<rect layer='{0}' " +
                      "transition='{1}' " +
                      "delay='1.2' " +
                      "duration='2.2' " +
                      "x='20' " +
                      "y='40' " +
                      "width='100' " +  
                      "height='200' " +
                      "rotation='10' " +
                      "fill_color='ffffff' " +
                      "fill_alpha='2' " +
                      "line_color='f0f0f0' " +
                      "line_alpha='1' " +
                      "line_thickness='2' " +
                      "/>";
            DrawRectangle rectangle = new DrawRectangle();
            rectangle.Layer = layer;
            rectangle.Transition = type;
            rectangle.Delay = 1.2;
            rectangle.Duration = 2.2;
            rectangle.X = 20;
            rectangle.Y = 40;
            rectangle.Width = 100;
            rectangle.Height = 200;
            rectangle.Rotation = 10;
            rectangle.FillColor = "ffffff";
            rectangle.FillAlpha = 2;
            rectangle.LineColor = "f0f0f0";
            rectangle.LineAlpha = 1;
            rectangle.LineThickness = 2;
            Assert.AreEqual(
                string.Format(testXml, layer.ToString(), type.ToString()),
                rectangle.ToSourceXML());
        }
    }
}
